package com.andreas.shop.controller;

import com.andreas.shop.common.ApiRestResponse;
import com.andreas.shop.exception.ShopBussinessException;
import com.andreas.shop.service.OrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author andreaszhou
 * @ClassName AdminOrderController
 * @Description TODO
 * @date 2021/2/2 19:41
 * @Version 1.0
 */
@RestController
public class AdminOrderController {
    @Resource
    OrderService orderServiceImp;

    @GetMapping("admin/order/list")
    @ApiOperation("管理员订单列表")
    @ResponseBody
    public ApiRestResponse listForAdmin(@RequestParam("pageNum") Integer pageNum,
                                        @RequestParam("pageSize") Integer pageSize) {
        PageInfo pageInfo = orderServiceImp.listForAdmin(pageNum, pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    @ApiOperation("管理员订单发货")
    @PostMapping("/admin/order/delivered")
    @ResponseBody
    public ApiRestResponse delivered (@RequestParam("orderNo") String orderNo){
        try {
            orderServiceImp.delivered(orderNo);
        } catch (ShopBussinessException e) {
            e.printStackTrace();
            return ApiRestResponse.error(e.getCode(),e.getMessage());
        }
        return ApiRestResponse.success();
    }

}
